package Member.selevrct;

import Member.entiy.Member;
import Member.servise.MemberSers;
import Member.servise.impl.MemberSerImpl;
import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@WebServlet("/MemberServletLogin")
public class MemberServletLogin extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");

        String pageStr=request.getParameter("page");
        String pagesizeStr=request.getParameter("pageSize");

        int page=pageStr!=null? Integer.parseInt(pageStr):1;
        int pageSize=pagesizeStr!=null? Integer.parseInt(pagesizeStr):4;

        MemberSers cs=new MemberSerImpl();
        List<Member> resultList=cs.getList(page,pageSize);
        int count=cs.getCount();
        int pageCount=count% pageSize==0?count/pageSize:(count/pageSize)+1;

        Map<Object,Object> pageMap = new HashMap<>();

        pageMap.put("resultList",resultList);
        pageMap.put("pageCount",pageCount);//总记录数
        pageMap.put("page",page);//页数
        pageMap.put("pageSize",pageSize);


        PrintWriter out=response.getWriter();
        out.print(JSON.toJSONString(pageMap));
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}